package cn.school.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author oldliu
 * @since 1.0
 */
@WebServlet("/regYundouServlet")
public class YundouRegServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        req.setCharacterEncoding("utf-8");//中文
        out.write("<html>");
        out.write("<head>");

        out.write("</head>");

        out.write("<body>");
        out.write("<h1>");
        out.print("您的注册信息如下:");
        out.write("</h1>");
        //
        String ip=req.getRemoteAddr();
        out.write("<h1>");
        out.print("ip:"+ip);
        out.write("</h1>");
        String name=req.getParameter("userName");
        String userPass=req.getParameter("userPass");
        String s=req.getParameter("sex");
        String phone=req.getParameter("phone");
        String []like=req.getParameterValues("like");
        out.write("<h3>");
        out.print("姓名:"+name);
        out.write("</h3>");
        out.write("<h3>");
        out.print("密码:"+userPass);
        out.write("</h3>");
        out.write("<h3>");
        out.print("性别:"+s);
        out.write("</h3>");
        out.write("<h3>");
        out.print("手机号:"+phone);
        out.write("</h3>");
        out.write("<h3>");
        out.print("你的爱好:");
        for(int i=0;like!=null&&i<like.length;i++)
            out.print(like[i]+"&nbsp;&nbsp;");
        out.write("</h3>");

        out.write("</body>");
        out.write("</html>");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
